/**
 *  test17.c - Test for PWM.
 *
 *  Copyright (C) 2008-2010 ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#include "include/core.h"
#include "drivers/uart_console.h"
#include "drivers/chdev.h"
#include "drivers/timer.h"
#include "devs.h"


void Main(void)
{
    chdev_t *dev = NULL;
    char_t ch = 0;
    timer_duty_cycle_t arg;
    arg.cycle = 1000;
    arg.high_duration = 50;

    dev = CDevOpen(TIMER0);
    if(dev == NULL) {
        Print("Cann't open TIMER0!\n");
        return;
    }
    CDevIoctl(dev, TIMER_CMD_STOP, NULL);
    CDevIoctl(dev, TIMER_CMD_CHG, &arg);

    do {
        Print("Please press any key to start, and ESC to exit!\n");
        while(!(ch = RevByte())) {
            ;
        }
        if(ch == 0x1B) { // ESC
            break;
        }

        CDevIoctl(dev, TIMER_CMD_START, NULL);
        Print("Please press any key to stop!\n\n");
        while(!(ch = RevByte())) {
            ;
        }
        CDevIoctl(dev, TIMER_CMD_STOP, NULL);
    } while(1);

    CDevClose(dev);
    Print("Test is Over!\n");
}

